﻿using UnityEngine;
using System.Collections;

public class gameController : MonoBehaviour {

	private Material[] materials;
	public bool red = true;
	public bool blue = true;
	public bool green = true;
	public float lives = 2.0f;

	// Use this for initialization
	void Start () {
		materials = (gameObject.GetComponent ("MeshRenderer") as MeshRenderer).sharedMaterials;
		Color color;
		for (int i = 0; i < materials.Length; i++){
			color = materials[i].GetColor("_Color");
			color.r = 255;
			color.b = 255;
			color.g = 255;
			materials[i].SetColor("_Color", color);
		}
	}
	
	// Update is called once per frame
	void FixedUpdate () {
		if (Input.GetButtonDown ("Fire3")) {
			if(red){
				cutOffRed();		
				red = false;
			}
			else{
				connectRed ();
				red = true;
			}
		}
		if (Input.GetButtonDown ("Fire2")) {
			if(blue){
				cutOffBlue();		
				blue = false;
			}
			else{
				connectBlue ();
				blue = true;
			}
		}
		if (Input.GetButtonDown ("Jump")) {
			if(green){
				cutOffGreen();		
				green = false;
			}
			else{
				connectGreen ();
				green = true;
			}
		}
	}

	public void cutOffRed(){
		Color color;
		for (int i = 0; i < materials.Length; i++){
			color = materials[i].GetColor("_Color");
			color.r = 0;
			materials[i].SetColor("_Color", color);
		}
	}

	public void connectRed(){
		Color color;
		for (int i = 0; i < materials.Length; i++){
			color = materials[i].GetColor("_Color");
			color.r = 255;
			materials[i].SetColor("_Color", color);
		}
	}

	public void cutOffBlue(){
		Color color;
		for (int i = 0; i < materials.Length; i++){
			color = materials[i].GetColor("_Color");
			color.b = 0;
			materials[i].SetColor("_Color", color);
		}
	}

	public void connectBlue(){
		Color color;
		for (int i = 0; i < materials.Length; i++){
			color = materials[i].GetColor("_Color");
			color.b = 255;
			materials[i].SetColor("_Color", color);
		}
	}

	public void cutOffGreen(){
		Color color;
		for (int i = 0; i < materials.Length; i++){
			color = materials[i].GetColor("_Color");
			color.g = 0;
			materials[i].SetColor("_Color", color);
		}
	}
	
	public void connectGreen(){
		Color color;
		for (int i = 0; i < materials.Length; i++){
			color = materials[i].GetColor("_Color");
			color.g = 255;
			materials[i].SetColor("_Color", color);
		}
	}
}
